package web.servlet.logincheckcode.dao;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import web.servlet.logincheckcode.domin.User;
import web.servlet.logincheckcode.util.JDBCUtils;


/**
 * @Author Administrator
 * @Date 2020/6/9 14:50
 **/
public class UserDaoImpl implements UserDao {
    JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    String sql = " ";

    @Override
    public User login(String username, String password) {
        try {
            sql = "select *from user where username=? and password=?";
            User user = template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class),username,password);
            return user;
        }catch (Exception E){
            System.out.println(E.getMessage());
            return null;
        }
    }

    @Override
    public int register(String username, String password) {
        sql="insert into user(username,password) values(?,?)";
        int i = template.update(sql, username, password);
        return i;
    }
}
